<?php
/**
 * 
 * @author: peng.shan <peng.shan@happyelements.com>
 * @version $Id: UcApi.php 295800 2013-01-29 09:46:44Z peng.shan $
 */
class UcApi{
    
    private $app_name = 'it';
    private $app_key = 'gdmrj7l6';
  //    private $request_url = 'http://10.130.132.240/uc2/api/';
 	private $request_url = 'http://local.ucenter2/admin/api/';

    public function get_userinfo_by_name($username) {
		$url = $this->request_url.'user.php?action=get_userinfo_by_name&name='.$username.'&app_name='.$this->app_name.'&app_key='.$this->app_key;
		
		$arr = json_decode(file_get_contents($url),true);
		if(!empty($arr)&&($arr['errno']==0)) {
			return $arr['result'];
		} else {
			return false;
		}
	}
	
	public function get_userinfo_by_unique_id($unique_id) {
		$url = $this->request_url.'user.php?action=get_userinfo_by_unique_id&unique_id='.$unique_id.'&app_name='.$this->app_name.'&app_key='.$this->app_key;
		$arr = json_decode(file_get_contents($url),true);
		if(!empty($arr)&&($arr['errno']==0)) {
			return $arr['result'];
		} else {
			return false;
		}
	}
	
	public function get_department() {
		$url = $this->request_url.'department.php?action=get_department&name='.$username.'&app_name='.$this->app_name.'&app_key='.$this->app_key;
		$arr = json_decode(file_get_contents($url),true);
		if(!empty($arr)&&($arr['errno']==0)) {
			return $arr['result'];
		} else {
			return false;
		}
	}
	
	public function get_group() {
		$url = $this->request_url.'department.php?action=get_group&name='.$username.'&app_name='.$this->app_name.'&app_key='.$this->app_key;
		$arr = json_decode(file_get_contents($url),true);
		if(!empty($arr)&&($arr['errno']==0)) {
			return $arr['result'];
		} else {
			return false;
		}
	}
	
	public function get_code() {
		$url = $this->request_url.'code.php?action=get_code&name='.$username.'&app_name='.$this->app_name.'&app_key='.$this->app_key;
		$arr = json_decode(file_get_contents($url),true);
		if(!empty($arr)&&($arr['errno']==0)) {
			return $arr['result'];
		} else {
			return false;
		}
	}
	
	public function get_user_managers($unique_id) {
		$url = $this->request_url.'user.php?action=get_user_managers&unique_id='.$unique_id.'&app_name='.$this->app_name.'&app_key='.$this->app_key;
		$arr = json_decode(file_get_contents($url),true);
		if(!empty($arr)&&($arr['errno']==0)) {
			return $arr['result'];
		} else {
			return false;
		}
	}
	/**
	 * 根据员工号得到用户code信息
	 * @param string $unique_id
	 * @return array 
	 */
	public function get_user_code_by_unique_id($unique_id){
	    $url = $this->request_url.'user.php?action=get_user_code_by_unique_id&unique_id='.$unique_id.'&app_name='.$this->app_name.'&app_key='.$this->app_key;
	    $arr = json_decode(file_get_contents($url),true);
	    if(!empty($arr)&&($arr['errno']==0))
		    return $arr['result'];
	    else
		    return false;
	}
	public function getUserInfoByUniqueId($users){
		 $url = $this->request_url.'user.php?action=get_users_multi&users='.implode(',',$users).'&app_name='.$this->app_name.'&app_key='.$this->app_key;
		  $arr = json_decode(file_get_contents($url),true);
	    if(!empty($arr)&&($arr['errno']==0))
		    return $arr['result'];
	    else
		    return false;
	}
	
	
	
	
}
